package com.briup.day22;

import com.briup.day10.bean.F;

import java.io.File;
import java.io.FileFilter;

public class Test_FileFor {
    public static void main(String[] args) {
        //1.准备目录文件
        File fileDir = new File("D:\\test");
        //2.使用list方法获取文件字符串数组
        String[] list = fileDir.list();
        System.out.println(list);
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
        //3.准备普通文件
        String f1 ="test.txt";
        File f2=new File(fileDir,f1);
        list=f2.list();
        System.out.println(list);
        //4.调用listFiles得到子文件file对象 数组
        File[] files = fileDir.listFiles();
        System.out.println(files);
        for (File f : files) {
            System.out.println(f+"子文件file");
        }
        System.out.println("=++++++++++++++++++++++++++++++++++++++++++=");
        File[] files1= fileDir.listFiles(new FileFilter() {
            public boolean accept(File file) {
                if(file.isFile()){
                    return true;
                }
                return false;
            }
        });
        for(File f : files1){
            System.out.println(f.getName());
        }
    }
}
